package com.code.monitor.constants;

import lombok.Data;

@Data
public class ResultEntity<T> {
    private String code;

    private String message;

    private T data;

    public static <T> ResultEntity success(T data) {
        ResultEntity resultEntity = new ResultEntity();
        resultEntity.setCode(ResultCode.SUCCESS.getCode());
        resultEntity.setData(data);
        return resultEntity;
    }

    public static <T> ResultEntity fail(ResultCode resultCode) {
        return fail(resultCode.getCode(), resultCode.getMessage(), null);
    }

    public static <T> ResultEntity fail() {
        return fail(ResultCode.ERROR.getCode(), ResultCode.ERROR.getMessage(), null);
    }

    public static <T> ResultEntity fail(String msg) {
        return fail(ResultCode.ERROR.getCode(), null, msg);
    }

    public static <T> ResultEntity fail(String code, String message, T data) {
        ResultEntity resultEntity = new ResultEntity();
        resultEntity.setCode(code);
        resultEntity.setMessage(message);
        resultEntity.setData(data);
        return resultEntity;
    }

}
